const express = require('express');
const login = require('../models/login');
const router = new express.Router();

//注册
router.post('/register',async(req,res)=>{
    console.log(req.body);
    const {user_name,password} = req.body;
    const user_name_reg = /^[A-Za-z][A-Za-z0-9.]{6,15}$/
    const user_password_reg = /^[A-Za-z0-9.]{6,15}$/
    // console.log(user_name_reg.test(user_name));
    if(user_name_reg.test(user_name)&&user_password_reg.test(password)){
        try{
            await login.create(req.body);
            res.send('注册成功');
        }
        catch(e){
            console.log(e);
            res.send('你网不好，重注册一遍');
        }
    }
    else{
        res.send('用户名或密码不正确');
    }
})

//登陆
router.post('/login',(req,res)=>{

})


module.exports = router;